﻿using System;
using System.Collections.Generic;

using System.Text;
using TimKen.DataEntity;
using System.Data.SqlClient;
using System.Data;

namespace TimKen.DataAccess
{

        /// <summary>
        /// 数据访问类CustomerDiscount。
        /// </summary>
        public class CustomerDiscountDAO
        {
            public CustomerDiscountDAO()
            { }
            #region  成员方法
            /// <summary>
            /// 是否存在该记录
            /// </summary>
            public bool Exists(int CustomerID, int StrategyID)
            {
                int rowsAffected;
                SqlParameter[] parameters = {
					new SqlParameter("@CustomerID", SqlDbType.Int,4),
					new SqlParameter("@StrategyID", SqlDbType.Int,4)};
                parameters[0].Value = CustomerID;
                parameters[1].Value = StrategyID;

                int result = DbHelperSQL.RunProcedure("UP_CustomerDiscount_Exists", parameters, out rowsAffected);
                if (result == 1)
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }

            /// <summary>
            /// 得到一个对象实体
            /// </summary>
            public CustomerDiscount GetModel(int CustomerID, int StrategyID)
            {
                SqlParameter[] parameters = {
					new SqlParameter("@CustomerID", SqlDbType.Int,4),
					new SqlParameter("@StrategyID", SqlDbType.Int,4)};
                parameters[0].Value = CustomerID;
                parameters[1].Value = StrategyID;

                CustomerDiscount model = new CustomerDiscount();
                DataSet ds = DbHelperSQL.RunProcedure("UP_CustomerDiscount_GetModel", parameters, "ds");
                if (ds.Tables[0].Rows.Count > 0)
                {
                    if (ds.Tables[0].Rows[0]["CustomerID"].ToString() != "")
                    {
                        model.CustomerID = int.Parse(ds.Tables[0].Rows[0]["CustomerID"].ToString());
                    }
                    if (ds.Tables[0].Rows[0]["StrategyID"].ToString() != "")
                    {
                        model.StrategyID = int.Parse(ds.Tables[0].Rows[0]["StrategyID"].ToString());
                    }
                    if (ds.Tables[0].Rows[0]["StrategyType"].ToString() != "")
                    {
                        model.StrategyType = int.Parse(ds.Tables[0].Rows[0]["StrategyType"].ToString());
                    }
                    if (ds.Tables[0].Rows[0]["Discount"].ToString() != "")
                    {
                        model.Discount = decimal.Parse(ds.Tables[0].Rows[0]["Discount"].ToString());
                    }
                    return model;
                }
                else
                {
                    return null;
                }
            }

            /// <summary>
            /// 获得数据列表
            /// </summary>
            public DataSet GetList(string strWhere)
            {
                StringBuilder strSql = new StringBuilder();
                strSql.Append("select CustomerID,StrategyID,StrategyType,Discount ");
                strSql.Append(" FROM CustomerDiscount ");
                if (strWhere.Trim() != "")
                {
                    strSql.Append(" where " + strWhere);
                }
                return DbHelperSQL.Query(strSql.ToString());
            }

            /*
            /// <summary>
            /// 分页获取数据列表
            /// </summary>
            public DataSet GetList(int PageSize,int PageIndex,string strWhere)
            {
                SqlParameter[] parameters = {
                        new SqlParameter("@tblName", SqlDbType.VarChar, 255),
                        new SqlParameter("@fldName", SqlDbType.VarChar, 255),
                        new SqlParameter("@PageSize", SqlDbType.Int),
                        new SqlParameter("@PageIndex", SqlDbType.Int),
                        new SqlParameter("@IsReCount", SqlDbType.Bit),
                        new SqlParameter("@OrderType", SqlDbType.Bit),
                        new SqlParameter("@strWhere", SqlDbType.VarChar,1000),
                        };
                parameters[0].Value = "CustomerDiscount";
                parameters[1].Value = "ID";
                parameters[2].Value = PageSize;
                parameters[3].Value = PageIndex;
                parameters[4].Value = 0;
                parameters[5].Value = 0;
                parameters[6].Value = strWhere;	
                return DbHelperSQL.RunProcedure("UP_GetRecordByPage",parameters,"ds");
            }*/

            #endregion  成员方法
        
    }
}
